package com.xp.tinyurl.admin.auth;

import org.springframework.stereotype.Component;

/**
 * @Description user
 * @Author chengguo.pei
 * @Date 2021/9/22 12:00
 */
@Component
public class UserThreadLocal {

    // jdk建议将 ThreadLocal 定义为 private static ，这样就不会有弱引用，内存泄漏的问题了
    private static ThreadLocal<String> userThreadLocal = new ThreadLocal<>();

    public String get(){
        return userThreadLocal.get();
    }

    public void set(String userName){
        userThreadLocal.set(userName);
    }

    public void remove(){
        userThreadLocal.remove();
    }

}
